{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## modles\n",
    "自定义  注意不能跟内置模块同名\n",
    "内置模块  直接import\n",
    "第三方模块 pip安装的 \n",
    "\n",
    "默认查找模块的路径 可以自已增加\n",
    "- 当前py文件（脚本）所在目录中。\n",
    "- 内置模块中找\n",
    "- site-packages中"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:\\Users\\wsl\n",
      "C:\\Users\\wsl\\miniconda3\\python311.zip\n",
      "C:\\Users\\wsl\\miniconda3\\DLLs\n",
      "C:\\Users\\wsl\\miniconda3\\Lib\n",
      "C:\\Users\\wsl\\miniconda3\n",
      "\n",
      "C:\\Users\\wsl\\miniconda3\\Lib\\site-packages\n",
      "C:\\Users\\wsl\\miniconda3\\Lib\\site-packages\\win32\n",
      "C:\\Users\\wsl\\miniconda3\\Lib\\site-packages\\win32\\lib\n",
      "C:\\Users\\wsl\\miniconda3\\Lib\\site-packages\\Pythonwin\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "\n",
    "for item in sys.path:\n",
    "    print(item)\n",
    "\n",
    "# D:\\code\\code\\python\\day01.base"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T03:41:50.768652700Z",
     "start_time": "2024-01-15T03:41:50.759550500Z"
    }
   },
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 运行时的参数 xxx.py  sys.argv=[0]\n",
    "name = sys.argv[1]\n",
    "age = sys.argv[2]\n",
    "token = sys.argv[3]\n",
    "\n",
    "data_string = \"{}-{}\".format(name, token)\n",
    "print(data_string)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 模块中的`__name__`\n",
    "\n",
    "每个模块中都有一个 `__name__`的内部变量\n",
    "\n",
    "- 当我们运行模块时，`__name__ = \"__main__\"`\n",
    "- 当我们导入模块时，`__name__ = \"模块名\"`"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "# 主函数\n",
    "def run():\n",
    "    print(\"hello world\")\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    run()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T05:08:44.215906400Z",
     "start_time": "2024-01-15T05:08:44.174726100Z"
    }
   },
   "execution_count": 4
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 内置模块"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### random"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15\n",
      "0.9009183137373027\n",
      "33\n",
      "[44, 33]\n",
      "[1111, 88, 1, 12, 99]\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "v1 = random.randint(10, 20)  # 1.随机整数\n",
    "print(v1)\n",
    "\n",
    "v2 = random.uniform(0, 1)  # 2.随机小数\n",
    "print(v2)\n",
    "\n",
    "v3 = random.choice([11, 22, 33, 44])  # 3.随机选择一个数\n",
    "print(v3)\n",
    "\n",
    "v4 = random.sample([11, 22, 33, 44], 2)  # 4.随机选择多个数\n",
    "print(v4)  # [11, 33]\n",
    "\n",
    "num_list = [1, 99, 12, 88, 1111]  # 5.打乱顺序\n",
    "random.shuffle(num_list)\n",
    "print(num_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T05:14:01.057481100Z",
     "start_time": "2024-01-15T05:14:01.047808Z"
    }
   },
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "v1 = random.randint(65, 90)\n",
    "data = chr(v1)\n",
    "print(data)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T05:15:41.668798800Z",
     "start_time": "2024-01-15T05:15:41.626234500Z"
    }
   },
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "import string\n",
    "\n",
    "data = random.choice(string.ascii_letters)\n",
    "print(data)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T05:15:50.252169Z",
     "start_time": "2024-01-15T05:15:50.214174700Z"
    }
   },
   "execution_count": 7
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "恭喜：员工-297、员工-256、员工-183、员工-24、员工-234获得三等奖，奖品是：赠送ipad\n",
      "恭喜：员工-69、员工-85、员工-129获得二等奖，奖品是：赠送iphone 14\n",
      "恭喜：员工-247获得一等奖，奖品是：马尔代夫\n",
      "恭喜：员工-66获得特等奖，奖品是：一套房\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "# 1.创建300个员工\n",
    "users = ['员工-{}'.format(i) for in range(1, 301)]\n",
    "\n",
    "# 2.奖项和人数\n",
    "data_list = [\n",
    "    (\"三等奖\", 5, \"赠送ipad\"),\n",
    "    (\"二等奖\", 3, \"赠送iphone 14\"),\n",
    "    (\"一等奖\", 1, \"马尔代夫\"),\n",
    "    (\"特等奖\", 1, \"一套房\"),\n",
    "]\n",
    "\n",
    "# 3.抽奖\n",
    "for title, count, detail in data_list:\n",
    "    input(\"请抽奖>>>\")\n",
    "\n",
    "    # 3.1 抽人  [\"xx\",\"xx\"]\n",
    "    lucky_list = random.sample(users, count)\n",
    "\n",
    "    # 3.2 剔除\n",
    "    for name in lucky_list:\n",
    "        users.remove(name)\n",
    "\n",
    "    # 3.3 展示信息\n",
    "    message = \"恭喜：{}获得{}，奖品是：{}\".format(\"、\".join(lucky_list), title, detail)\n",
    "    print(message)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T05:18:53.634004500Z",
     "start_time": "2024-01-15T05:18:39.125940400Z"
    }
   },
   "execution_count": 8
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### hashlib\n",
    "可以实现md5加密,md5不能解密\n",
    "弱密码容易撞库"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21232f297a57a5a743894a0e4a801fc3\n"
     ]
    }
   ],
   "source": [
    "import hashlib\n",
    "\n",
    "data = \"admin\"\n",
    "\n",
    "obj = hashlib.md5()\n",
    "obj.update(data.encode('utf-8'))\n",
    "res = obj.hexdigest()\n",
    "print(res)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T05:26:22.032782400Z",
     "start_time": "2024-01-15T05:26:22.023659200Z"
    }
   },
   "execution_count": 9
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 加盐 \n",
    "加后缀"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "31e6d3515f3380198e95b4bf83e5c4ee\n"
     ]
    }
   ],
   "source": [
    "data = \"admin\"\n",
    "\n",
    "obj = hashlib.md5(\"asdfasdfasdfasdfa3exc\".encode('utf-8'))\n",
    "obj.update(data.encode('utf-8'))\n",
    "res = obj.hexdigest()\n",
    "print(res)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T05:30:35.541534600Z",
     "start_time": "2024-01-15T05:30:35.498217500Z"
    }
   },
   "execution_count": 10
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 用户注册+写入文件\n",
    "user = input(\"输入用户名：\")\n",
    "pwd = input(\"输入密码：\")\n",
    "\n",
    "# 2.加密密码\n",
    "obj = hashlib.md5(\"asdfasdfasdfasdfa3exc\".encode('utf-8'))\n",
    "obj.update(pwd.encode('utf-8'))\n",
    "password = obj.hexdigest()\n",
    "\n",
    "# 3.写入文件\n",
    "with open(\"db.txt\", mode='a', encoding='utf-8') as f:\n",
    "    line = \"{}|{}\\n\".format(user, password)\n",
    "    f.write(line)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T05:43:40.506961100Z",
     "start_time": "2024-01-15T05:43:36.130515Z"
    }
   },
   "execution_count": 11
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "nt\n",
      "C:\\Users\\wsl\\python-wsl\n",
      "wsl\n",
      "['myfile.log', 'myrollog.log']\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "print(os.name)\n",
    "print(os.getcwd())\n",
    "print(os.getlogin())\n",
    "print(os.listdir(\"d:/logs\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "D:\\conda\\lib\\site-packages\\ipykernel_launcher.py\n",
      "win32\n",
      "['', 'D:\\\\conda\\\\python36.zip', 'D:\\\\conda\\\\DLLs', 'D:\\\\conda\\\\lib', 'D:\\\\conda', 'D:\\\\conda\\\\lib\\\\site-packages', 'D:\\\\conda\\\\lib\\\\site-packages\\\\win32', 'D:\\\\conda\\\\lib\\\\site-packages\\\\win32\\\\lib', 'D:\\\\conda\\\\lib\\\\site-packages\\\\Pythonwin', 'D:\\\\conda\\\\lib\\\\site-packages\\\\IPython\\\\extensions', 'C:\\\\Users\\\\wsl\\\\.ipython']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<module 'sys' (built-in)>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "import importlib\n",
    "\n",
    "print(sys.argv[0])\n",
    "print(sys.platform)\n",
    "print(sys.path)\n",
    "importlib.reload(sys)"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 时间模块\n",
    "time"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-01-15T06:45:50.608264900Z",
     "start_time": "2024-01-15T06:45:50.560841300Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1705301150.5592418\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "\n",
    "print(time.time())"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "time.sleep(1)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.0\n"
     ]
    }
   ],
   "source": [
    "start = time.time()\n",
    "end = time.time()\n",
    "\n",
    "interval = end - start\n",
    "print(interval)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T06:47:11.929427300Z",
     "start_time": "2024-01-15T06:47:11.884950500Z"
    }
   },
   "execution_count": 25
  },
  {
   "cell_type": "markdown",
   "source": [
    "datetime"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-01-15 14:48:01.194142\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "data = datetime.now()\n",
    "print(data)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T06:48:01.243122600Z",
     "start_time": "2024-01-15T06:48:01.196141800Z"
    }
   },
   "execution_count": 26
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-11-24 22:36:36.601864\n"
     ]
    }
   ],
   "source": [
    "from datetime import timedelta\n",
    "\n",
    "v1 = datetime.now() - timedelta(days=50, hours=40, minutes=10, seconds=100)\n",
    "print(v1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T06:48:16.644647500Z",
     "start_time": "2024-01-15T06:48:16.602947100Z"
    }
   },
   "execution_count": 27
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-01-15 14:48:50\n",
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "v1 = datetime.now()\n",
    "v2 = v1.strftime(\"%Y-%m-%d %H:%M:%S\")\n",
    "\n",
    "print(v2)  # \"2022-07-16 14:26:25\"\n",
    "print(type(v2))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T06:48:50.106341800Z",
     "start_time": "2024-01-15T06:48:50.063040800Z"
    }
   },
   "execution_count": 28
  },
  {
   "cell_type": "markdown",
   "source": [
    "练习"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "#案例：用户注册&存储文件&注册时间\n",
    "from datetime import datetime\n",
    "\n",
    "user = input(\"用户名：\")\n",
    "pwd = input(\"密码：\")\n",
    "ctime_string = datetime.now().strftime(\"%Y年%m月%d日\")\n",
    "\n",
    "line = \"{}|{}|{}\\n\".format(user, pwd, ctime_string)\n",
    "\n",
    "with open('db.txt', mode='a', encoding='utf-8') as f:\n",
    "    f.write(line)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "#案例：日志写入到不同文件，按天来分割\n",
    "from datetime import datetime\n",
    "\n",
    "while True:\n",
    "    user = input(\"用户名：\")\n",
    "    pwd = input(\"密码：\")\n",
    "\n",
    "    line = \"{}|{}\\n\".format(user, pwd)\n",
    "\n",
    "    ctime_string = datetime.now().strftime(\"%Y-%m-%d-%H-%M-%S\")\n",
    "    file_name = \"{}.txt\".format(ctime_string)\n",
    "\n",
    "    with open(file_name, mode='a', encoding='utf-8') as f:\n",
    "        f.write(line)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "转换\n",
    "![jupyter](./png/img_3.png)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2022-01-12 00:00:00\n"
     ]
    }
   ],
   "source": [
    "# 字符串 -> datetime类型\n",
    "text = \"2022-01-12\"\n",
    "res = datetime.strptime(text, \"%Y-%m-%d\")\n",
    "print(res)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T07:10:15.670013800Z",
     "start_time": "2024-01-15T07:10:15.577505700Z"
    }
   },
   "execution_count": 29
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-01-15\n"
     ]
    }
   ],
   "source": [
    "# datetime类型 -> 字符串\n",
    "res = datetime.now().strftime(\"%Y-%m-%d\")\n",
    "print(res)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T07:10:47.939329300Z",
     "start_time": "2024-01-15T07:10:47.891288800Z"
    }
   },
   "execution_count": 30
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1705302687.899539\n"
     ]
    }
   ],
   "source": [
    "# datetime类型 -> 时间戳\n",
    "res = datetime.now().timestamp()\n",
    "print(res)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T07:11:27.952823900Z",
     "start_time": "2024-01-15T07:11:27.900641500Z"
    }
   },
   "execution_count": 31
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-01-15 15:11:54.347492\n"
     ]
    }
   ],
   "source": [
    "# 时间戳 - > datetime类型\n",
    "v1 = time.time()\n",
    "res = datetime.fromtimestamp(v1)\n",
    "print(res)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T07:11:54.359187200Z",
     "start_time": "2024-01-15T07:11:54.348492900Z"
    }
   },
   "execution_count": 32
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9:46:00\n",
      "35160\n"
     ]
    }
   ],
   "source": [
    "# 考勤\n",
    "start_string = \"2022-04-11 08:47\"\n",
    "start_date = datetime.strptime(start_string, \"%Y-%m-%d %H:%M\")\n",
    "\n",
    "end_string = \"2022-04-11 18:33\"\n",
    "end_date = datetime.strptime(end_string, \"%Y-%m-%d %H:%M\")\n",
    "\n",
    "v1 = end_date - start_date\n",
    "print(v1)\n",
    "\n",
    "print(v1.seconds)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T07:14:30.606419100Z",
     "start_time": "2024-01-15T07:14:30.549275300Z"
    }
   },
   "execution_count": 33
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## json\n",
    "python java  or 其他语言 都可用通用的双引json格式传输"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "序列化，Python数据类型 -> JSON格式字符串"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"code\": 100, \"data\": [11, 22, 33]}\n"
     ]
    }
   ],
   "source": [
    "info = {'code': 100, \"data\": [11, 22, 33]}  # python中支持单双引  java中只有双引\n",
    "\n",
    "import json\n",
    "\n",
    "data_string = json.dumps(info)\n",
    "print(data_string)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T05:57:22.879661200Z",
     "start_time": "2024-01-15T05:57:22.871843200Z"
    }
   },
   "execution_count": 13
  },
  {
   "cell_type": "markdown",
   "source": [
    "反序列化，  JSON格式字符串 -> Python数据类型"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 100, 'data': [11, 22, 33]}\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "data_string = '{\"code\": 100, \"data\": [11, 22, 33]}'\n",
    "\n",
    "import json\n",
    "\n",
    "info = json.loads(data_string)\n",
    "print(info)\n",
    "print(info['code'])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T06:06:58.101800700Z",
     "start_time": "2024-01-15T06:06:58.052124Z"
    }
   },
   "execution_count": 14
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"name\": \"武沛齐\", \"k2\": 456, \"status\": true}\n"
     ]
    }
   ],
   "source": [
    "info = {\"name\": \"武沛齐\", \"k2\": 456, \"status\": True}\n",
    "\n",
    "import json\n",
    "\n",
    "res = json.dumps(info, ensure_ascii=False)  # 关闭中文转换为unicode\n",
    "print(res)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T06:10:04.363789900Z",
     "start_time": "2024-01-15T06:10:04.284294300Z"
    }
   },
   "execution_count": 15
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "v1 = '{\"k1\":123,\"k2\":456}'  # 是JSON格式的字符串\n",
    "v2 = \"{'k1':123,'k2':456}\"  # 不是JSON格式的字符串\n",
    "v3 = '{\"k1\":123,\"k2\":456,\"k3\":[11,22,33]}'  # 是JSON格式的字符串\n",
    "v4 = '{\"k1\":123,\"k2\":456,\"k3\":(11,22,33)}'  # 不是JSON格式的字符串\n",
    "\n",
    "v5 = '{\"k1\": 123, \"k2\": 456, \"status\": true}'  # 是JSON格式的字符串\n",
    "v6 = '{\"k1\": 123, \"k2\": 456, \"status\": True}'  # 不是JSON格式的字符串\n",
    "\n",
    "v7 = '{\"name\": \"武沛齐\", \"k2\": 456, \"status\": true, \"data\": null}'  # 是JSON格式的字符串\n",
    "v8 = '{\"name\": \"武沛齐\", \"k2\": 456, \"status\": true, \"data\": None}'  # 不是JSON格式的字符串"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "   序列化支持类型\n",
    "    +-------------------+---------------+\n",
    "    | Python            | JSON          |\n",
    "    +===================+===============+\n",
    "    | dict              | object        |\n",
    "    +-------------------+---------------+\n",
    "    | list, tuple       | array         |\n",
    "    +-------------------+---------------+\n",
    "    | str               | string        |\n",
    "    +-------------------+---------------+\n",
    "    | int, float        | number        |\n",
    "    +-------------------+---------------+\n",
    "    | True              | true          |\n",
    "    +-------------------+---------------+\n",
    "    | False             | false         |\n",
    "    +-------------------+---------------+\n",
    "    | None              | null          |\n",
    "    +-------------------+---------------+"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "import demjson\n",
    "\n",
    "json1 = \"{x:1, y:2, z:3}\"\n",
    "data = demjson.decode(json1)\n",
    "print(data)\n",
    "\n",
    "json2 = \"{'x':1, 'y':2, 'z':3}\"\n",
    "\n",
    "json3 = '{\"x\":1, \"y\":2, \"z\":3}'  # 默认只有这种正确\n",
    "json.loads(json3)\n",
    "\n",
    "data = [{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}]\n",
    "print(demjson.encode(data))\n",
    "\n",
    "json = '{\"a\":1,\"b\":2,\"c\":3,\"d\":4,\"e\":5}';\n",
    "print(demjson.decode(json))"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "练习"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "留校联盟 https://movie.douban.com/subject/35496212/\n",
      "五月十二月 https://movie.douban.com/subject/35295277/\n",
      "名侦探柯南：黑铁的鱼影 https://movie.douban.com/subject/35873969/\n",
      "偷破天际线 https://movie.douban.com/subject/35874112/\n",
      "夜幕将至 https://movie.douban.com/subject/35211474/\n",
      "绿夜 https://movie.douban.com/subject/36217770/\n",
      "河边的错误 https://movie.douban.com/subject/35256092/\n",
      "感恩节 https://movie.douban.com/subject/3775098/\n",
      "芭比 https://movie.douban.com/subject/4058939/\n",
      "过往人生 https://movie.douban.com/subject/34963356/\n",
      "长安三万里 https://movie.douban.com/subject/36035676/\n",
      "坚如磐石 https://movie.douban.com/subject/33447633/\n",
      "拯救嫌疑人 https://movie.douban.com/subject/35875180/\n",
      "断网假期 https://movie.douban.com/subject/35151492/\n",
      "艾琳 https://movie.douban.com/subject/35729829/\n",
      "蜘蛛侠：纵横宇宙 https://movie.douban.com/subject/30391186/\n",
      "梦想情景 https://movie.douban.com/subject/36076190/\n",
      "饥饿游戏：鸣鸟与蛇之歌 https://movie.douban.com/subject/34438298/\n",
      "照明商店 https://movie.douban.com/subject/36086210/\n",
      "网络谜踪2 https://movie.douban.com/subject/34795100/\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "\n",
    "res = requests.get(\n",
    "    url=\"https://movie.douban.com/j/search_subjects?type=movie&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=20&page_start=20\",\n",
    "    headers={\n",
    "        \"user-agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36\"\n",
    "    }\n",
    ")\n",
    "# 豆瓣返回的原始JSON格式的字符串\n",
    "# print(res.text)\n",
    "\n",
    "# 反序列化为Python中的数据-> 字典\n",
    "data_dict = json.loads(res.text)\n",
    "\n",
    "# 对字典进行操作\n",
    "for item in data_dict['subjects']:\n",
    "    title = item['title']\n",
    "    url = item['url']\n",
    "    print(title, url)\n",
    "    with open('movies.txt', mode='a', encoding='utf-8') as f:\n",
    "        f.write(\"{}|{}\\n\".format(title, url))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T06:25:37.400973300Z",
     "start_time": "2024-01-15T06:25:36.667740Z"
    }
   },
   "execution_count": 20
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## OS模块"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "db\\root\\a.txt\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "# 路径拼接\n",
    "path = os.path.join(\"db\", 'root', \"a.txt\")\n",
    "print(path)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T07:23:28.264679600Z",
     "start_time": "2024-01-15T07:23:28.180709100Z"
    }
   },
   "execution_count": 34
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "db\\root\n"
     ]
    }
   ],
   "source": [
    "# 获取文件夹路径\n",
    "folder_path = os.path.dirname(path)\n",
    "print(folder_path)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-15T07:23:56.680072300Z",
     "start_time": "2024-01-15T07:23:56.624869900Z"
    }
   },
   "execution_count": 35
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 当前脚本的绝对路径\n",
    "print(__file__)\n",
    "base_dir = os.path.dirname(os.path.abspath(__file__))\n",
    "file_path = os.path.join(base_dir, 'a1.txt')\n",
    "\n",
    "print(file_path)"
   ],
   "metadata": {
    "collapsed": false
   },
   "execution_count": null
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 获取文件夹下的所有文件和文件夹\n",
    "res = os.listdir(r\"D:\\learn\")\n",
    "print(res)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 判断路径是否存在\n",
    "v1 = os.path.exists(\"路径是否存在\")\n",
    "print(v1)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 创建文件夹\n",
    "folder_path = \"xxx/xxxx/xxxx\"\n",
    "if not os.path.exists(folder_path):\n",
    "    os.makedirs(folder_path)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 判断是否是文件夹\n",
    "v1 = os.path.isdir(file_path)\n",
    "print(v1)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "os.remove(file_path)  # 删除文件"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "import shutil\n",
    "\n",
    "shutil.rmtree(db_path)  # 删除文件夹"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 查看目录下的所有文件和文件夹(一级目录)\n",
    "import os\n",
    "\n",
    "base_dir = os.path.dirname(os.path.abspath(__file__))\n",
    "db_path = os.path.join(base_dir, 'db')\n",
    "\n",
    "for name in os.listdir(db_path):\n",
    "    file_path = os.path.join(db_path, name)\n",
    "    print(name)\n",
    "    print(file_path)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 查看目录下的文件和文件夹（多级目录）\n",
    "import os\n",
    "\n",
    "base_dir = os.path.dirname(os.path.abspath(__file__))\n",
    "db_path = os.path.join(base_dir, 'db')\n",
    "\n",
    "for in_path, folder_list, name_list in os.walk(db_path):\n",
    "    for name in name_list:\n",
    "        abs_path = os.path.join(in_path, name)\n",
    "        print(abs_path)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### shutil"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "import shutil\n",
    "\n",
    "shutil.rmtree(\"文件夹的路径\")  #删除文件夹\n",
    "shutil.move(\"db.txt\", 'news.txt')  # 重命名\n",
    "shutil.copytree(\"yy\", \"db/yy\")  #拷贝\n"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## RE模块 正则"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['s42662578@qq.com', 'xxxxx@live.com']\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "\n",
    "text = \"wslabc楼主太牛逼了，在线想要 s42662578@qq.com 和 xxxxx@live.com谢谢楼主，手机号也可15131255789，搞起来呀wslabc\"\n",
    "\n",
    "# 邮箱  w任意字母、数字、下划线\n",
    "result = re.findall(r\"\\w+@\\w+\\.\\w+\", text, re.ASCII)\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-16T02:10:03.791014Z",
     "start_time": "2024-01-16T02:10:03.738025800Z"
    }
   },
   "execution_count": 42
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "email = input(\"邮箱：\")\n",
    "\n",
    "is_valid = re.match(r\"^\\w+@\\w+\\.\\w+$\", email)\n",
    "if is_valid:\n",
    "    print(\"格式合法\")\n",
    "else:\n",
    "    print(\"格式错误\")"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['wsl', 'wsl']\n"
     ]
    }
   ],
   "source": [
    "# 查找固定字符\n",
    "data_list = re.findall(r\"wsl\", text)\n",
    "print(data_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-16T02:10:08.412358700Z",
     "start_time": "2024-01-16T02:10:08.375153700Z"
    }
   },
   "execution_count": 43
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['wsla', 'wsla']\n"
     ]
    }
   ],
   "source": [
    "# 含特定字符 wsla  wslb  wsli\n",
    "data_list = re.findall(r\"wsl[abi]\", text)\n",
    "print(data_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-16T02:10:19.612379200Z",
     "start_time": "2024-01-16T02:10:19.524381Z"
    }
   },
   "execution_count": 45
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['ws', 'ws']\n"
     ]
    }
   ],
   "source": [
    "data_list = re.findall(r\"w[a-z]\", text)\n",
    "print(data_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-16T02:12:53.342343200Z",
     "start_time": "2024-01-16T02:12:53.267210100Z"
    }
   },
   "execution_count": 46
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "data_list = re.findall(r\"t[0-9]\", text)\n",
    "print(data_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-16T02:13:20.134323800Z",
     "start_time": "2024-01-16T02:13:20.044582700Z"
    }
   },
   "execution_count": 47
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 手机号  数字\n",
    "result = re.findall(r\"\\d{11}\", text)\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "result = re.findall(r\"\\d{2,}\", text)\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "result = re.findall(r\"t\\d?\", text)  # ? 0个或1个\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "result = re.findall(r\"t\\d+\", text)  # 1个或n个\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "result = re.findall(r\"t\\d*\", text)  # 0个或n个\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## requests"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"code\":0,\"data\":{\"count\":15630,\"next\":\"/api/v1/result/enroll/?limit=1&offset=21&resultType=enroll\",\"previous\":\"/api/v1/result/enroll/?limit=1&offset=19&resultType=enroll\",\"result\":[{\"stu_info\":{\"username\":\"林**\",\"avatar\":\"//hcdn2.luffycity.com/media/frontend/head_portrait/logo@2x.png\",\"company\":\"茂**安\",\"position\":\"维修技师\"},\"enroll_course\":\"Python开发副业山顶会\",\"enroll_level\":\"中级\",\"review_date\":\"2024-01-14\",\"why_take_this_course\":\"学多门技术  增加收入\",\"why_choose_us\":\"缘分\",\"your_expectation\":\"学到知识   提高收入\"}]}}\n",
      "{'Date': 'Tue, 16 Jan 2024 08:49:41 GMT', 'Content-Type': 'application/json', 'Content-Length': '565', 'Connection': 'keep-alive', 'allow': 'GET, HEAD, OPTIONS', 'vary': 'Cookie, Origin', 'x-frame-options': 'DENY', 'x-content-type-options': 'nosniff', 'referrer-policy': 'same-origin', 'Server': 'WAF /antiddos', 'X-Cache-Status': 'MISS'}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "res = requests.get(\n",
    "    url=\"https://api.luffycity.com/api/v1/result/enroll/?resultType=enroll&limit=1&offset=20\",\n",
    "    headers={\n",
    "        \"user-agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\",\n",
    "    }\n",
    ")\n",
    "\n",
    "# 响应体\n",
    "res.encoding = 'utf-8'\n",
    "print(res.text)\n",
    "\n",
    "# 响应头\n",
    "print(res.headers)\n",
    "\n",
    "data_dict = res.json()\n",
    "\n",
    "for ele in data_dict['data']:\n",
    "    id = ele['count']\n",
    "    title = ele['next']\n",
    "    print(id, title)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-16T08:49:41.092182800Z",
     "start_time": "2024-01-16T08:49:40.519951200Z"
    }
   },
   "execution_count": 55
  },
  {
   "cell_type": "markdown",
   "source": [
    "## xml"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "rank {'updated': 'yes'} 2\n",
      "year {} 2023\n",
      "gdppc {} 141100\n",
      "neighbor {'direction': 'E', 'name': 'Austria'} None\n",
      "neighbor {'direction': 'W', 'name': 'Switzerland'} None\n",
      "country {'name': 'Liechtenstein'}\n",
      "country {'name': 'Panama'}\n"
     ]
    }
   ],
   "source": [
    "text = \"\"\"\n",
    "<data>\n",
    "    <country name=\"Liechtenstein\">\n",
    "        <rank updated=\"yes\">2</rank>\n",
    "        <year>2023</year>\n",
    "        <gdppc>141100</gdppc>\n",
    "        <neighbor direction=\"E\" name=\"Austria\" />\n",
    "        <neighbor direction=\"W\" name=\"Switzerland\" />\n",
    "    </country>\n",
    "     <country name=\"Panama\">\n",
    "        <rank updated=\"yes\">69</rank>\n",
    "        <year>2026</year>\n",
    "        <gdppc>13600</gdppc>\n",
    "        <neighbor direction=\"W\" name=\"Costa Rica\" />\n",
    "        <neighbor direction=\"E\" name=\"Colombia\" />\n",
    "    </country>\n",
    "</data>\n",
    "\"\"\"\n",
    "\n",
    "from xml.etree import ElementTree\n",
    "\n",
    "root = ElementTree.XML(text)\n",
    "\n",
    "node = root.find(\"country\")\n",
    "for child in node:\n",
    "    print(child.tag, child.attrib, child.text)\n",
    "\n",
    "node_list = root.findall(\"country\")\n",
    "for node in node_list:\n",
    "    print(node.tag, node.attrib)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-18T08:18:19.774510900Z",
     "start_time": "2024-01-18T08:18:19.687449200Z"
    }
   },
   "execution_count": 7
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "rank {'updated': 'yes'} 2\n",
      "year {} 2023\n",
      "gdppc {} 141100\n",
      "neighbor {'direction': 'E', 'name': 'Austria'} None\n",
      "neighbor {'direction': 'W', 'name': 'Switzerland'} None\n"
     ]
    }
   ],
   "source": [
    "from xml.etree import ElementTree\n",
    "\n",
    "root = ElementTree.XML(text)\n",
    "\n",
    "node = root.find(\"country\")\n",
    "for child in node:\n",
    "    print(child.tag, child.attrib, child.text)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-18T08:16:46.404835500Z",
     "start_time": "2024-01-18T08:16:46.328388Z"
    }
   },
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'ToUserName': '武沛齐', 'FromUserName': 'root', 'CreateTime': '1348831860', 'MsgType': 'text', 'Content': '吃饭了', 'MsgId': '1234567890123456', 'MsgDataId': 'xxxx', 'Idx': '11'}\n"
     ]
    }
   ],
   "source": [
    "text = \"\"\"\n",
    "<xml>\n",
    "  <ToUserName>武沛齐</ToUserName>\n",
    "  <FromUserName>root</FromUserName>\n",
    "  <CreateTime>1348831860</CreateTime>\n",
    "  <MsgType>text</MsgType>\n",
    "  <Content>吃饭了</Content>\n",
    "  <MsgId>1234567890123456</MsgId>\n",
    "  <MsgDataId>xxxx</MsgDataId>\n",
    "  <Idx>11</Idx>\n",
    "</xml>\n",
    "\"\"\"\n",
    "data_dict = {}\n",
    "root = ElementTree.XML(text)\n",
    "for node in root:\n",
    "    data_dict[node.tag] = node.text\n",
    "\n",
    "print(data_dict)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-18T08:18:39.556867600Z",
     "start_time": "2024-01-18T08:18:39.466209100Z"
    }
   },
   "execution_count": 8
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 虚拟环境\n",
    "引入第三方模块时新建虚拟环境，一般在linux操作，不需要配置环境变量"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "1.linux"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "pip install virtualenv  # 安装工具包\n",
    "cd envs   #进入虚拟环境目录\n",
    "virtualenv crm --python=python3.12.0     # 创建虚拟环境并进入\n",
    "activate  #激活\n",
    "deactivate  # 退出"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "F:\\envs\\crm\n",
    "    python.exe\n",
    "    Scripts\n",
    "\t\tpip.exe\n",
    "\t\tactivate.exe  (激活环境)\n",
    "\tLib\n",
    "    \tsite-packages\n",
    "    \t\t..."
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "2.pycharm"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "新建项目和环境：\n",
    "    项目：D:\\code\\cj\n",
    "    虚拟环境：D:\\code\\cj\\.venv\n",
    "\n",
    "pip install requests\n",
    "pip freeze > requirements.txt"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "打开代码时：\n",
    "设置-add  创建虚拟环境\n",
    "pip install -r requirements.txt  # 安装依赖包  "
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "![jupyter](./png/img_8.png)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
